<script>
	import utils from '@/utils/util.js';
	
	import {
		storeToRefs
	} from 'pinia';
	import {
		useUserStore
	} from '@/store'
	
	export default {
		globalData: {
			showPrivacy: false,
			tabbarIndex: 0
		},
		onLaunch: function() {
			console.log('App Launch')
			// uni.hideTabBar({});
			let UserStore = useUserStore();
			
			//--更新用户缓存信息
			uni.getStorage({
				key: 'usemall_member',
				success: (res) => {
					console.log("更新用户缓存信息", res);
					if (JSON.stringify(res.data) == '{}') {
						UserStore.logout();
						return;
					}
					let datas = {
						member: {
							member_headimg: res.data.member_headimg,
							member_name: res.data.member_name,
							member_id: res.data.member_id,
							member_access_token: res.data.member_access_token,
							member_mobile: res.data.member_mobile,
							member_nickname: res.data.member_nickname,
							member_rid: res.data.member_rid,
							ORG: res.data.ORG || '',
							ORGID: res.data.ORGID || '',
							state: res.data.state,
							is_plus: res.data.is_plus,
							member_openid: res.data.member_openid,
							member_weixin: res.data.member_weixin
						},
						user: {
							uid: res.data.member_id,
							token: "",
							tokenExpired: "",
							userInfo: {
								mobile: res.data.member_mobile,
								role: ['member'],
								username: res.data.member_mobile,
								user_id: res.data.member_id
							}
						}
					}
					console.log(datas);
					UserStore.login(datas);
				},
				fail: (res) => {
					console.log(res)
				}
			})
			
			uni.getSystemInfo({
				success: (e) => {
					console.log("获取设备信息", e, e.platform);
					let systemInfo = {};
					// this.compareVersion(e.SDKVersion, '2.5.0')
					let statusBar = 0 //状态栏高度
					let customBar = 0 // 状态栏高度 + 导航栏高度  
					let navbar = 0 // 自定义标题与胶囊对齐高度
					let platform = e.platform;
			
					// #ifdef MP
					statusBar = e.statusBarHeight
					customBar = e.statusBarHeight + 45
					if (e.platform === 'android') {
						// this.$store.commit('SET_SYSTEM_IOSANDROID', false)
						customBar = e.statusBarHeight + 50
					}
					// #endif
			
			
					// #ifdef MP-WEIXIN
					statusBar = e.statusBarHeight
					const custom = wx.getMenuButtonBoundingClientRect()
					customBar = custom.bottom + custom.top - e.statusBarHeight
			
					navbar = (custom.top - e.statusBarHeight) * 2 + custom.height
					// #endif
			
			
					// #ifdef MP-ALIPAY
					statusBar = e.statusBarHeight
					customBar = e.statusBarHeight + e.titleBarHeight
					// #endif
			
			
					// #ifdef APP-PLUS
					console.log('app-plus', e)
					statusBar = e.statusBarHeight
					customBar = e.statusBarHeight + 45
					// #endif
			
			
					// #ifdef H5
					statusBar = 0
					customBar = e.statusBarHeight + 45
					// #endif
					systemInfo = {
						statusBar: statusBar,
						customBar: customBar,
						screenHeight: e.screenHeight,
						screenWidth: e.screenWidth,
						navbar: navbar,
						terminal: platform
					};
					UserStore.upSystemInfo(systemInfo);
				}
			})
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	/*每个页面公共css */
	@import '@/common/uni.css';
	@import '@/common/app.css';
	@import '@/common/common.css';
</style>
